<template>
  <nav-bar>
    <div slot="center" class="title">
      <!-- 利用遍历，把title展示在导航栏上 -->
      <!-- 利用currentIndex和绑定点击事件,决定点击谁,谁就有active的类 -->
      <div v-for="(item,index) in titles" :key="index"
           class="title-item"
           :class="{active:index === currentIndex}"
           @click="titleClick(index)">
        {{item}}
      </div>
    </div>
    <div slot="left" class="back" @click="backClick">
      <img src="~assets/img/common/back.svg">
    </div>
  </nav-bar>
</template>

<script>
import NavBar from 'components/common/navbar/NavBar'

export default {
  name:'DetailNavBar',
  components:{
    NavBar
  },
  data(){
    return {
      // titles是导航栏上面四个标题的内容
      titles:['商品','参数','评论','推荐'],
      currentIndex:0
    }
  },
  methods:{
    titleClick(index){
      this.currentIndex = index;
      // 为了标题跳到对应的内容，需要把发生点击的标题的index传出去
      this.$emit('titleClick',index)
    },
    backClick(){
      this.$router.back()
    }
  }
}
</script>
<style scoped>
.title{
  display: flex;
  font-size: 13px;
}
.title-item{
  flex:1
}
.active{
  color:var(--color-high-text)
}

.back img{
  margin-top:10px;
}
</style>
